package com.xdclass.mysql.interceptor;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Properties;

@Intercepts(@Signature(type = Executor.class,method = "query",
        args = {MappedStatement.class, Object.class,
                RowBounds.class, ResultHandler.class}))
public class QueryInterceptor1 implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Long startTime = System.currentTimeMillis();
        System.out.println("拦截方法开始，SQL执行");
        Object proceed = invocation.proceed();
        System.out.println("拦截方法结束，SQL执行时间："+
                (System.currentTimeMillis()-startTime) + "ms");
        return proceed;
    }

    @Override
    public Object plugin(Object o) {
        return Plugin.wrap(o,this);
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
